package crond

import (
	"context"
	"device-admin/config/mysql"
	"device-admin/internal/models"
	"time"

	db_sharding "192.168.1.75/go-pkg/db-sharding"
)

// DBSharding 定期分表
func DBSharding() error {
	db := mysql.NewDB()
	// 95开发日志，按日保存。最多保存3天
	db_sharding.ShardAndDropTable(context.Background(), db, models.DevEventLogTpl{}, db_sharding.Day, time.Hour*24*3)
	// 95操作日志，按月保存。最多保存1个月
	db_sharding.ShardAndDropTable(context.Background(), db, models.DeviceLogTpl{}, db_sharding.Month, time.Hour*24*30)
	// 热力图，按月保存，最多保存3个月
	db_sharding.ShardAndDropTable(context.Background(), db, models.DeviceHeatMapTpl{}, db_sharding.Month, time.Hour*24*30*3)
	// 环境因子，按月保存，最多保存1个月
	db_sharding.ShardAndDropTable(context.Background(), db, models.DeviceMetricTpl{}, db_sharding.Month, time.Hour*24*30)
	// 告警记录，按月保存，最多保存1个月
	db_sharding.ShardAndDropTable(context.Background(), db, models.AlarmNotifyRecordTpl{}, db_sharding.Month, time.Hour*24*30)
	return nil
}
